Pause and Resume and get the value of a countdown timer by savedInstanceState [closed]

Posted by Catherine grace Balauro on Programmers See other posts from Programmers or by Catherine grace Balauro
Published on 2011-12-01T03:13:57Z Indexed on 2011/12/01 10:22 UTC
Read the original article Hit count: 264

Filed under:
|

I have developed a countdown timer and I am not sure how to pause and resume the timer as the TextView for the timer is being clicked. Click to start then click again to pause and to resume, click again the timer's text view.

This is my code:

Timer = (TextView)this.findViewById(R.id.time); //TIMER  
Timer.setOnClickListener(TimerClickListener);  
counter = new MyCount(600000, 1000);  
}//end of create 

private OnClickListener TimerClickListener = new OnClickListener() {  
public void onClick(View v) {  
updateTimeTask();       }  

private void updateTimeTask() {  
if (decision==0){  
counter.start();  
decision=1;}  
else if(decision==2){  
counter.onResume1();  
decision=1; }  
else{  
counter.onPause1();  
decision=2; }//end if  
};  };  

class MyCount extends CountDownTimer {  
public MyCount(long millisInFuture, long countDownInterval) {  
super(millisInFuture, countDownInterval);  
}//MyCount  
public void onResume1(){  
onResume(); }  
public void onPause1() {  
onPause();}  
public void onFinish() {  
Timer.setText("00:00");  
p1++;  
if (p1<=4){  
TextView PScore = (TextView) findViewById(R.id.pscore);  
PScore.setText(p1 + "");  
}//end if  
}//finish  
public void onTick(long millisUntilFinished) {  
Integer milisec = new Integer(new Double(millisUntilFinished).intValue());  
Integer cd_secs = milisec / 1000;  

Integer minutes = (cd_secs % 3600) / 60;  
Integer seconds = (cd_secs % 3600) % 60;    

Timer.setText(String.format("%02d", minutes) + ":"  
+ String.format("%02d", seconds));  
//long timeLeft = millisUntilFinished / 1000;  
}//on tick  
}//class MyCount  

protected void onResume() {  
super.onResume();  
//handler.removeCallbacks(updateTimeTask);  
//handler.postDelayed(updateTimeTask, 1000);  
}//onResume  

@Override  
protected void onPause() {  
super.onPause();  
//do stuff  
}//onPause  

I am only beginner in android programming and I don't know how to get the value of the countdown timer using savedInstanceState. How do I do this?

© Programmers or respective owner

Related posts about java

Related posts about android